﻿using System.Drawing;
using System.Windows.Forms;

namespace Sai.UI
{
    public class EmptyListView : ListView
    {
        const int DrawBackground = 20;

        public string MessageWhenEmpty
        {
            get;
            set;
        }

        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            if (m.Msg == DrawBackground)
            {
                if (this.Items.Count == 0)
                {
                    Graphics g = this.CreateGraphics();
                    string msg = MessageWhenEmpty;

                    if (!string.IsNullOrEmpty(msg))
                    {
                        int width = (this.Width - g.MeasureString(msg, this.Font).ToSize().Width) / 2;
                        g.DrawString(msg, this.Font, SystemBrushes.ControlText, width, 30);
                    }
                }
            }
        }
    }

}
